#include"quaternion.h"
// quaternion::quaternion(num _w, num _x, num _y, num _z){ w = _w;x = _x;y = _y;z = _z; }
// quaternion::quaternion(std::initializer_list<num> in){
// 	auto i = in.begin();	w = *(i++);	x = *(i++);	y = *(i++);	z = *i;
// }
// quaternion::quaternion(num re){ w = re;x = y = z = 0; }


quaternion operator+(const quaternion& a, const quaternion& b){
	return quaternion{ a.w + b.w,a.x + b.x,a.y + b.y,a.z + b.z };
}
quaternion operator-(const quaternion& a, const quaternion& b){
	return quaternion{ a.w - b.w,a.x - b.x,a.y - b.y,a.z - b.z };
}
quaternion operator-(const quaternion& a){
	return{-a.w,-a.x,-a.y,-a.z};
}
quaternion operator+(const quaternion& quat,quaternion::num real){
	return {quat.w+real,quat.x,quat.y,quat.z};
}
quaternion operator+(quaternion::num real,const quaternion& quat){
	return {quat.w+real,quat.x,quat.y,quat.z};
}
quaternion operator-(const quaternion& quat,quaternion::num real){
	return {quat.w-real,quat.x,quat.y,quat.z};
}
quaternion operator-(quaternion::num real,const quaternion& quat){
	return {real-quat.w,-quat.x,-quat.y,-quat.z};
}
quaternion operator*(const quaternion& a, const quaternion& b){
	quaternion res;
	res.w = a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z;
	res.x = a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y;
	res.y = a.w * b.y + a.y * b.w + a.z * b.x - a.x * b.z;
	res.z = a.w * b.z + a.z * b.w + a.x * b.y - a.y * b.x;
	return res;
}
quaternion operator*(const quaternion& quat,quaternion::num real){
	return {quat.w*real,quat.x*real,quat.y*real,quat.z*real};
}
quaternion operator*(quaternion::num real,const quaternion& quat){
	return {quat.w*real,quat.x*real,quat.y*real,quat.z*real};
}

quaternion dot(const quaternion& a, const quaternion& b){
	return quaternion{ a.w * b.w , a.x * b.x , a.y * b.y , a.z * b.z };
}

quaternion::num quaternion::mod(){
	return sqrt(w*w+x*x+y*y+z*z);
}

quaternion quaternion::conjugate(){
	return quaternion{w,-x,-y,-z};
}

